/*
 * @Author: hrg
 * @Date: 2024-01-31 16:08:52
 * @LastEditTime: 2024-02-01 10:25:36
 * @FilePath: \study_go\study09_gin\gin_dome_03\main.go
 * @Description:  结构体验证
 */

package main

import (
	"github.com/gin-gonic/gin"
)

type Person struct {
	Age  int    `json:"age" binding:"required,gt=10"`
	Name string `json:"name" binding:"required"`
}

func main() {
	// 创建路由
	r := gin.New()

	r.POST("/person", PersonFunc)

	r.Run(":9090")

}

func PersonFunc(c *gin.Context) {
	var p1 Person

	err := c.ShouldBind(&p1)
	if err != nil {
		c.JSON(500, gin.H{
			"error:": err.Error(),
		})
		return
	}

	c.JSON(200, p1)

}
